from django.db import models
from django.contrib.auth import get_user_model
from guardian.shortcuts import get_perms
# Create your models here.

from movie.models import MovieDetail

User = get_user_model()


class UserStarMovie(models.Model):
    """
    用户对电影的评分,一个用户可以对多个电影评分,一部电影也可以拥有多个用户的评分,用户评分之后就不能再去评分这个电影了
    """

    STAR = (
        ('1', ''),
        ('2', ''),
        ('3', ''),
        ('4', ''),
        ('5', ''),
        ('6', ''),
        ('7', ''),
        ('8', ''),
        ('9', ''),
        ('10', ''),
    )
    user = models.ForeignKey(User, verbose_name='评论用户', help_text='评论用户')
    movie = models.ForeignKey(MovieDetail, verbose_name='所属电影', help_text='所属电影')
    star = models.CharField(max_length=2, choices=STAR, verbose_name='用户对电影的评分', help_text='用户对电影的评分')

    class Meta:
        verbose_name = '用户评论一部电影'
        verbose_name_plural = verbose_name

        unique_together = ("user", "movie")


class UserFavMovie(models.Model):
    """
    用户点赞一个电影
    """

    user = models.ForeignKey(User, verbose_name='点赞用户', help_text='点赞用户')
    movie = models.ForeignKey(MovieDetail, verbose_name='所属电影', help_text='所属电影')

    class Meta:
        verbose_name = '用户点赞一个电影'
        verbose_name_plural = verbose_name

        unique_together = ("user", "movie")



class UserMovieShortComments(models.Model):
    """
    用户对一个电影进行评论
    """

    user = models.ForeignKey(User, verbose_name='评论用户', help_text='评论用户')
    movie = models.ForeignKey(MovieDetail, verbose_name='评论的电影', help_text='评论的电影')
    comments = models.TextField(max_length=255, verbose_name='短评的内容', help_text='短片的内容')
    add_time = models.DateTimeField(auto_now=True, verbose_name='评论的时间', help_text='评论时间')
    reply_to = models.ForeignKey('self',verbose_name='回复某个评论',help_text='回复某个评论也可以不回复',null=True,default=None)

    class Meta:
        verbose_name = '用户对一个电影进行短评论'
        verbose_name_plural = verbose_name

        permissions = (
            ('can_not_add_shortcomments','用户不能去发帖'),
            ('can_delete_shortcomments','可以删帖'),
            ('can_update_shortcomments', '可以修改帖子'),
            ('can_read_shortcomments','可以查看帖子(个人中心)')

        )

